using System;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TMFileManager {
    public partial class TMFM : Form {

        public TMFM() {
            InitializeComponent();
            treeMap1.RootPathChanged += new EventHandler(treeMap1_RootPathChanged);
            treeMap1.DepthLevel = Properties.Settings.Default.DepthLevel;
            treeMap1.ShowFreeSpace = Properties.Settings.Default.ShowFreeSpace;

            treeMap2.RootPathChanged += new EventHandler(treeMap2_RootPathChanged);
            treeMap2.DepthLevel = Properties.Settings.Default.DepthLevel;
            treeMap2.ShowFreeSpace = Properties.Settings.Default.ShowFreeSpace;
            createMenu();
			textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
			textBox2.LostFocus += new EventHandler(textBox2_LostFocus);
        }
		
		private void textBox1_LostFocus(object sender, EventArgs e) {
			treeMap1.RootPath = textBox1.Text;
		}
		
		private void textBox2_LostFocus(object sender, EventArgs e) {
			treeMap2.RootPath = textBox2.Text;
		}

        void treeMap2_RootPathChanged(object sender, EventArgs e) {
            textBox2.Text = treeMap2.RootPath;
        }

        private void createMenu() {
            MainMenu mm = new MainMenu();
            MenuItem tools = new MenuItem("&Tools");
            mm.MenuItems.Add(tools);
            MenuItem options = new MenuItem("&Options");
            tools.MenuItems.Add(options);
            options.Click += new EventHandler(options_Click);
            this.Menu = mm;
        }

        void options_Click(object sender, EventArgs e) {
            Options options = new Options();
            if (options.ShowDialog() == DialogResult.OK) {
                treeMap1.DepthLevel = Properties.Settings.Default.DepthLevel;
                treeMap1.ShowFreeSpace = Properties.Settings.Default.ShowFreeSpace;
                treeMap2.DepthLevel = Properties.Settings.Default.DepthLevel;
                treeMap2.ShowFreeSpace = Properties.Settings.Default.ShowFreeSpace;
                treeMap1.ReloadColorScheme();
                treeMap2.ReloadColorScheme();
                treeMap1.RootPath = treeMap1.RootPath;
                treeMap2.RootPath = treeMap2.RootPath;
            }
        }

        void treeMap1_RootPathChanged(object sender, EventArgs e) {
            textBox1.Text = treeMap1.RootPath;
        }

        private void button1_Click(object sender, EventArgs e) {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = textBox1.Text;
            if (fbd.ShowDialog() == DialogResult.OK) {
                textBox1.Text = fbd.SelectedPath;
                treeMap1.RootPath = fbd.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e) {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = textBox1.Text;
            if (fbd.ShowDialog() == DialogResult.OK) {
                textBox2.Text = fbd.SelectedPath;
                treeMap2.RootPath = fbd.SelectedPath;
            }
        }
    }
}
